﻿@using Telerik.Web.Mvc
@using Telerik.Web.Mvc.UI
@using Presentation.Web.Admin
@model  IEnumerable<Domain.Dto.LogDto>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<html>
<head>
    <meta charset="utf-8" content="" />
    <title>系统日志</title>
    <link href="@Url.Content("~/Content/layout.css")" rel="stylesheet" type="text/css" />
    @*end css files   js files start *@
    <script src="@Url.Content("~/Scripts/jquery-1.8.0.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.23.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.blockUI.js")" type="text/javascript" ></script>
    <script type="text/javascript">
        $(function () {
            $('table').attr('style', 'font-size:12px;');
            $(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);
        });
    </script>
    @(Html.Telerik().StyleSheetRegistrar()
    .DefaultGroup(group => group
    .Add("2012.2.607/telerik.default.min.css")
    .Add("2012.2.607/telerik.common.min.css")
    .Add("2012.2.607/telerik.vista.min.css")
    .Add("2012.2.607/telerik.rtl.min.css")
    .Combined(true).Compress(true)))
</head>
<body>
    @{
        ViewBag.subtitle = "系统日志";
        ViewBag.title = "系统日志";
        Layout = "";
    }
    @{Html.Telerik().Grid(Model)
    .Name("LoggerGrid")
    .ToolBar(toolBar => toolBar.Template(
        @<text>
        @{
            if (Html.HasUiPermission(this.ViewContext, "muldelete"))
            { 
            <a href='javascript:;' class='t-button' onclick='mulDelete()'>删除选择项</a>
            }
            if (Html.HasUiPermission(this.ViewContext, ""))
            { }
        }
        <a href='javascript:;' class='t-button' onclick="history.go(-1)" style="float: right;
            margin-left: 15px; margin-right: 10px;">返回</a>
        @{
            if (Html.HasUiPermission(this.ViewContext, "clearall"))
            { 
            <a href='javascript:;' id="clearAllLog" class='t-button' style="float: right;">清空日志</a>
            }
        }
        </text>))
    .Columns(columns =>
    {
        columns.Template(@<text><input name="selectRow" type="checkbox" value="@item.Id " title="checkedRecords" /></text>)
        .HeaderTemplate(@<text><input type="checkbox" title="选择所有" id="checkAllRecords" /></text>)
        .HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:center" })
        .ClientTemplate("<input type=\"checkbox\" title=\"check all records\" name = 'selectRow' value = '<#= Id #>'/>").Width(20);

        columns.Bound(o => o.Id).Width(50).Title("系统Id");

        columns.Bound(o => o.TypeId).Width(50).Title("日志类型");
        columns.Bound(o => o.UserId).Width(20).Title("用户Id");
        columns.Bound(o => o.PageUrl).Width(100).Title("执行页面");
        columns.Bound(o => o.ReferrerUrl).Width(100).Title("上一页面");
        columns.Bound(o => o.ShortMessage).Width(150).Title("简介");
        columns.Bound(o => o.FullMessage).Title("详细");

        columns.Bound(o => o.IpAddress).Width(100).Title("添加IP").ReadOnly().Hidden();
        columns.Bound(o => o.AddTime).Format("{0:yyyy-MM-dd HH:mm:ss}").Width(100).Title("添加时间");

        columns.Bound(o => o.SortNum).Width(100).Title("排序号").Hidden();
        columns.Bound(o => o.State).Width(100).Title("状态").Hidden();
        columns.Command(comm =>
        {
            if (Html.HasUiPermission(this.ViewContext, "delete"))
            {
                comm.Delete().ButtonType(GridButtonType.Text);
            }
        }).Width(50).Title("删除");
    })
    .DataKeys(key => key.Add("Id"))//添加主键
    .ClientEvents(clientEvents => clientEvents.OnComplete("bindComplete"))
    .DataBinding(dataBinding => dataBinding.Ajax().Select("ajaxindex", "logger")
        .Delete("delete", "logger"))
    .Pageable(page => page.PageSize(10).Total(ViewBag.total))
    .EnableCustomBinding(true)
    .Render();
    }
    @(Html.Telerik().ScriptRegistrar().jQuery(false).jQueryValidation(false).DefaultGroup(group => group.Compress(false)))
    <script type="text/javascript">
        function mulDelete() {
            var delStr = $(':checked');
            if (delStr.length < 1) {
                alert('亲，您没有选择任何记录.');
                return;
            }
            var loggerGrid = $("#LoggerGrid").data("tGrid");
            var size = loggerGrid.pageSize;
            var page = loggerGrid.currentPage;

            jQuery.post('/logger/muldelete?pi=' + page + "&take=" + size, delStr, function (res) {
                if (res.success) {
                    setTimeout(function () {
                        $("#LoggerGrid").data("tGrid").dataBind(res.data);
                        $("#checkAllRecords").attr("checked", false);
                    }, 1000);
                } else {
                    alert(res.message);
                }
            });
        }

        function bindComplete(e) {
            $("input:checkbox[name='selectRow']").attr("checked", false);
            var success = e.response.success;
            if (success != null && success != undefined) {
                alert(e.response.message);
                window.location.reload();
            }
        }

        $(function () {
            $("input:checkbox[name='selectRow']").attr("checked", false);
            $('#checkAllRecords').click(function checkAll() { $("#LoggerGrid tbody input:checkbox[name='selectRow']").attr("checked", this.checked); });
            $('#clearAllLog').bind('click', function () {
                if (confirm("你确定要删除所有日志嘛？？？")) {
                    $.post('/logger/clearall', function (res) {
                        if (res.success) {
                            $("#LoggerGrid").data("tGrid").rebind();
                            alert('已成功清空日志');
                        }
                        else {
                            alert(res.message);
                        }
                    });
                }
            });
        });
    </script>
</body>
</html>
